home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / stayresc.zip / STAYRES.DOC < prev   
Text File  |  1985-10-24  |  4KB  |  68 lines

  1.  
  2.  
  3.                TERMINATE AND STAY RESIDENT
  4.                --------- --- ---- --------
  5.                   Brian Irvine
  6.  
  7.  
  8.    STAYRES.C was written for the Cware C Development System ( DeSmet C ).
  9. It uses library functions and other features ( such as in-line assembly
  10. language ) which might not be available with other C compilers.  However, the
  11. basic stuff is there and it should be a trivial task to convert it to be
  12. compilable under other C compilers.
  13.  
  14.    When a resident program takes over from DOS, if the program uses DOS I/O, it
  15. will most likely leave the local DOS stack and register values changed from
  16. what they were when the program gained control.  When control is returned to
  17. DOS, then it gets very confused and usually ends up doing something completely
  18. unpredictable, or just going off into j-space.    As a result, most programs
  19. which terminate and stay resident take care of their own disk and screen I/O,
  20. and are written in assembly language.  This does not have to be the case,
  21. however.  Programs can be written in high-level languages as long as a little
  22. stack management is performed before and after program use.
  23.  
  24.    The programming in STAYRES.C proposes one solution to the problem.  It saves
  25. the top of the DOS stack and all of the processor registers on the local
  26. program stack before the program is entered.  The program can then perform
  27. normal operations like disk access and formatted screen output.  On exit, all
  28. of the information saved on the local stack is transferred back to the DOS
  29. stack and to the processor registers, creating virtually the same machine state
  30. as was present before the program took control.
  31.  
  32.    STAYRES.C works by redirecting the BIOS INT 16H keyboard service routine
  33. vector to point to an internal routine.  The old INT 16H vector is moved to INT
  34. 67H so that it can be used by STAYRES.C itself.  Now when DOS issues a request
  35. for the next character from the queue, we can examine the character before
  36. passing it on to DOS.  If it is the character or keypress combination which we
  37. have designated as that required to activate the TSR program, then we make a
  38. further check to see if the program is already active.    If not, then we go
  39. through the process of saving the machine state, then call the entry point of
  40. the TSR program.
  41.  
  42.    The TSR code is contained in a module which requires the modification of
  43. only one line of code to suit the name of the function which will be designated
  44. as the main entry point to the program.  The module can then be compiled and
  45. linked in with any other object modules to produce a complete program.
  46.  
  47.    The code contained in STAYRES.C is inspired by a set of Turbo Pascal
  48. routines written by Lane H. Ferris.  I have taken the central idea of Lane's
  49. code and used it in this program.  The Turbo routines are available on the
  50. Borland SIG on Compuserve.
  51.  
  52.    I realize that I don't know all there is about this process, so if you have
  53. any further information you would like to impart, or if you have any comments
  54. or suggestions for modifications or improvements, please leave a message for me
  55. on Compuserve.    Use Easyplex or leave a message addressed to me on one of the
  56. IBM PC Sig's.
  57.  
  58.    I am releasing this code to the Public Domain so that others can use the
  59. information for non-profit purposes.  If you do use the code in any of your
  60. applications, I ask only that you give credit for the source.  Feel free to
  61. copy and distribute these files as you wish, but please ensure that the credits
  62. are included.
  63.  
  64.                     Brian Irvine
  65.                     3379 St Marys Place
  66.                     Santa Clara, CA 95051
  67.                     Compuserve User ID [71016,544]
  68.